<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" >

<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script type="text/javascript" th:src="@{/js/jquery-2.1.4.min.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap-3.3.7-dist/js/bootstrap.min.js}"></script>
<link type="text/css" rel="stylesheet" th:href="@{/js/bootstrap-3.3.7-dist/css/bootstrap.min.css}">
<script type="text/javascript" th:src="@{/js/bootstrap-treeview/bootstrap-treeview.min.js}"></script>
<link type="text/css" rel="stylesheet" th:href="@{/js/bootstrap-treeview/bootstrap-treeview.min.css}">
<script type="text/javascript" th:src="@{/js/bootStrap-addTabs/bootstrap.addtabs.min.js}"></script>
<link type="text/css" rel="stylesheet" th:href="@{/js/bootStrap-addTabs/bootstrap.addtabs.css}">
<script type="text/javascript" th:src="@{/js/bootstrap-table/bootstrap-table.min.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
<link type="text/css" rel="stylesheet" th:href="@{/js/bootstrap-table/bootstrap-table.min.css}">

<script type="text/javascript" th:src="@{/js/bootstrap-fileinput/js/fileinput.min.js}"></script>
<script th:src="@{/js/bootstrap-fileinput/js/locales/zh.js}"></script>

</head>
<body>

<div style="margin-left:10px;margin-top:10px;width:1000px;">
    <div class="panel panel-primary">
        <div class="panel-heading">
            <h3 class="panel-title">筛选搜索</h3>
        </div>
        <div class="panel-body">
            <div style="display:inline-block;">
                <div style="float:left;padding:6px;">
                    <span>输入搜索：</span>
                </div>
                <div style="float:left;">
                    <input id="order_id"  placeholder="订单编号"  class="form-control" style="width:200px;" />
                </div>
                <div style="float:left;padding:6px;">
                    <span>提交时间：</span>
                </div>
                <div style="float:left;">
                    <input    id="order_time"  placeholder="请选择时间"   type="date" style="width:200px;"  class="form-control"/>
                </div>
                <div style="float:left;padding:6px;">
                    <span>订单类型：</span>
                </div>
                <div style="float:left;">
                    <select  id="order_paystate" class="form-control" style="width:100px;"  >
                        <option value="">全部</option>
                        <option value="5">待付款</option>
                        <option value="1">待发货</option>
                        <option value="2">已发货</option>
                        <option value="3">已完成</option>
                        <option value="4">已关闭</option>
                    </select>
                </div>
                <div style="float:left;margin-left:30px;" >
                    <button onclick="query()" class="btn btn-primary" >查询搜索</button>
                    <button onclick="query()" class="btn btn-primary" >重置</button>
                </div>
            </div>
        </div>
    </div>
</div>

   <table id="myTable"></table>


</body>
<script>

    $(function (){
        quer();
    })

    // function chaxun(){
    //     $('#myTable').bootstrapTable('refresh');//刷新表格
    // }

    function  quer(){

     $("#myTable").bootstrapTable({
        url:"/GetOrderList",
        columns:[
            {title:"",checkbox:true},
            {field:"order_id",title:"编号"},
            {field:"order_money",title:"订单金额",formatter:function (value){
                return "￥"+value;
                }},
            //{field:"order_receiverinfo",title:"订单来源"},
            {field:"order_paystate",title:"订单状态",formatter:function (value,row,index){


                    if(value==5){return '待付款'};
                    if(value==1){return '待发货'};
                    if(value==2){return '已发货'};
                    if(value==3){return '已完成'};
                    if(value==4){return '已关闭'};
                }},
            {field:"order_time",title:"提交时间"},
            {field:"user_name",title:"用户账号"},
            {field:"order_numbered",title:"id"},
            {field:"operation",title:"操作",align:'center',width:150,formatter:function(value,row,index){
                    str='';
                    str1='';
                    if(row.order_paystate==2){
                        str +='<button type="button" onclick="del('+row.order_id+')" class="btn btn-danger">删除订单</button>'

                    }else {
                        str +='<button type="button" onclick="del('+row.order_id+')" class="btn btn-danger">删除订单</button>'
                        str1 +='<button type="button" onclick="ahuo('+row.order_numbered+')" class="btn btn-danger">发货</button>';
                    }

                    // if(row.order_paystate==5){
                    //     str +='<button class="btn btn-warning" data-toggle="modal" data-target="#myModal" onclick="huixian('+row.order_id+')">查看订单</button>'
                    //     str +='<button type="button" onclick="del('+row.order_id+')" class="btn btn-danger">关闭订单</button>'
                    // }
                    // if(row.order_paystate==1){
                    //     str +='<button class="btn btn-warning" data-toggle="modal" data-target="#myModal" onclick="huixian('+row.order_id+')">查看订单</button>'
                    //     str +='<button type="button" onclick="del('+row.order_id+')" class="btn btn-danger">订单发货</button>'
                    // }if(row.order_paystate==2 || row.order_paystate==3 ){
                    //     str +='<button class="btn btn-warning" data-toggle="modal" data-target="#myModal" onclick="huixian('+row.order_id+')">查看订单</button>'
                    //     str +='<button type="button" onclick="del('+row.order_id+')" class="btn btn-danger">订单追踪</button>'
                    // }if(row.order_paystate==4){
                    // str +='<button class="btn btn-warning" data-toggle="modal" data-target="#myModal" onclick="huixian('+row.order_id+')">查看订单</button>'


                    // }
                    return str+"       "+str1;
                }},
        ],
        pagination:true,
        pageSize:10,
        pageList:[2,4,6,8,10],
        sidePagination: "client",//前台开启分页
    })

     }




    /* 条查 */
    query = function() {
        $("#myTable").bootstrapTable("refresh", {
            "query": {
                order_id: $("#order_id").val(),
                order_paystate : $("#order_paystate").val(),
                order_time : $("#order_time").val(),
            }
        });
    }

    function ahuo(id) {
        $.ajax({
            url:"/adupPage",
            data:{id:id},
            success:function(){
                alert("修改成功")
                $("#myTable").bootstrapTable("refresh");//刷新表格
            },error:function(){
                // alert("删除成功")
                // $("#myTable").bootstrapTable("refresh");//刷新表格
            }

        });
    }

    function huixian(product_id){
        $("#myModal1").
        $.ajax({
            url:"getOrderItmeById",
            data:{id:product_id},
            type:"post",
            dataType:"json",
            success:function(data){
                $("#product_id").val(data.product_id);
                $("#product_name").val(data.product_name);
                $("#product_price").val(data.product_price);
                $("#product_category").val(data.product_category);
                $("#product_num").val(data.product_num);
                $("#product_description").val(data.product_description);
                $("#product_imgurl").val(data.product_imgurl);
                $("#file-Portrait").fileinput('refresh', {
                    initialPreview: "<img src="+data.product_imgurl+" height='180px' width='150px' class='file-preview-image'>",
                });
            }
        })
    }





    function del (ids){
       var arr= $("#myTable").bootstrapTable('getSelections');
        if (arr.length<=0){
            return "请选要删除的记录";
        }
        var ids = "";
        for (var t = 0; t < arr.length; t++) {
            ids += "," + arr[t]["order_id"];
        }
          ids = ids.substring(1);

        $.ajax({
            url:"/delOrder",
            data:{ids:ids},
            type:"post",
            success:function(){
                alert("删除成功")
                 $("#myTable").bootstrapTable("refresh");//刷新表格
            },error:function(){
               // alert("删除成功")
               // $("#myTable").bootstrapTable("refresh");//刷新表格
            }

        });
    }


    //新增

    function addUser(){
        //打开新增弹框
        bootbox.dialog({
            title: '新增用户',
            message: createAddContent("/toAddOrderPage"),
            closeButton: true,//是否显示关闭按钮
            buttons: {
                "success": {
                    "label": "<i class='icon-ok'></i> 保存",
                    "className": "btn-sm btn-success",
                    "callback": function () {
                        $.ajax({
                            url: '/addorder',
                            type: 'post',
                            cache:false,
                            data: $("#formId").serialize(),
                            success: function (data) {
                                if(data > 0){
                                    $("#myTable").bootstrapTable("refresh");//刷新表格
                                }else{
                                    alert("失败");
                                }
                                //刷新表格
                            }, error: function () {
                                alert("新增失败");
                            }
                        });
                    }
                },
                "cancel": {
                    "label": "<i class='icon-info'></i> 取消",
                    "className": "btn-sm btn-danger",
                    "callback": function () {

                    }
                }
            }

        });
    }













</script>
</html>